#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
string judge;
void solve()
{
	string s;
	cin>>n;
	cin>>s;

	if(judge.find(s)!=judge.npos) cout<<"YES"<<'\n';
	else cout<<"NO"<<'\n';

	
}

int main()
{
	close();
	int T; cin>>T;
	for(int i=0;i<1e5;i++)
	{
		if(i%3==0) judge+='F';
		if(i%5==0) judge+='B';

	}
	while (T--) solve();
	return 0;
}